﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Kugar.Core.Communications
{

    public abstract class MasterSlaveCommunicationEventArgsbase:EventArgs
    {
        protected MasterSlaveCommunicationEventArgsbase(Exception error)
        {
            Error = error;
            
        }

        public Exception Error { set; get; }

        public bool HasError { get { return Error != null; } }

        public virtual object UserState { get { return null; } }
    }


    public class MasterSendEventArgs : MasterSlaveCommunicationEventArgsbase
    {
        public MasterSendEventArgs(DataStructToSendBase sendedSData):this(sendedSData,null){}

        public MasterSendEventArgs(DataStructToSendBase sendedSData, Exception error)
            : base(error)
        {
            SendedSData = sendedSData;
        }

        public DataStructToSendBase SendedSData { get; private set; }

        public override object UserState
        {
            get
            {
                return SendedSData.UserState;
            }
        }
    }

    public class MasterReceiveEventArgs : MasterSlaveCommunicationEventArgsbase
    {
        public MasterReceiveEventArgs(DataStructToSendBase sendedSData, ArraySegment<byte> receiveData,Exception error):base(error)
        {
            SendedSData = sendedSData;
            ReceiveData = receiveData;
            ReceiveTime = DateTime.Now;
        }

        public DataStructToSendBase SendedSData { get; private set; }

        public ArraySegment<byte> ReceiveData { get; private set; }

        public DateTime ReceiveTime { get; private set; }

        public override object UserState
        {
            get
            {
                return SendedSData.UserState;
            }
        }
    }

    public class SlaveReceiveEventArgs : MasterSlaveCommunicationEventArgsbase
    {
        public SlaveReceiveEventArgs() : base(null){}

        public byte[] ReceiveData;

        public DateTime ReceiveTime;

    }




}
